import com.itheima.service.UserService;
import com.itheima.service.impl.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserApp {
    public static void main(String[] args) {
        //1.加载配置文件
        //ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
       //2.获取资源
       /* UserService userService = applicationContext.getBean("userService1", UserService.class);*/
       /* UserService userService1 = applicationContext.getBean("userService3", UserService.class);
        UserService userService2 = applicationContext.getBean("userService3", UserService.class);
        UserService userService3 = applicationContext.getBean("userService3", UserService.class);
        System.out.println(userService1==userService2);
        System.out.println(userService3==userService2);
        UserService userService4 = applicationContext.getBean("userService4", UserService.class);
        UserService userService5 = applicationContext.getBean("userService4", UserService.class);
        UserService userService6 = applicationContext.getBean("userService4", UserService.class);
        System.out.println(userService4==userService5);
        System.out.println(userService6==userService5);
        userService1.save();
        userService4.save();*/
        //ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
       //scope取值为singleton时测试
       //UserServiceImpl userService = applicationContext.getBean("userService", UserServiceImpl.class);
       //scope取值为prototype时测试
       // UserServiceImpl userService1 = applicationContext.getBean("userService", UserServiceImpl.class);
       // UserServiceImpl userService2 = applicationContext.getBean("userService2", UserServiceImpl.class);
        // UserServiceImpl userService3 = applicationContext.getBean("userService2", UserServiceImpl.class);
     /*  注：当scope的取值为singleton时，关闭容器对象就会执行destory方法，
           当scope的取值为prototype时，destory方法执行不会被看见，因为对象的销毁由垃圾回收机制控制，destory方法将不会被执行*/
        //applicationContext.close();

        //静态工厂创建bean对象
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
       /* UserServiceImpl userService1 = applicationContext.getBean("userService1", UserServiceImpl.class);*/
        //实例工厂创建bean对象 依赖工厂对象对应的bean
        UserServiceImpl userService2 = applicationContext.getBean("userService2", UserServiceImpl.class);
        userService2.save();


    }
}
